package by.grsu.coctails.db.tables;

import android.content.ContentValues;
import android.database.Cursor;
import by.grsu.coctails.model.db.CoctailDb;

public class CoctailsTable {
	public static final String NAME = "Coctails";

	private static final String[] COCTAILS_COLUMNS = { "ID", "Name", "History",
			"DrinkInstruction", "Image" };

	public static final int ID_COLUMN_INDEX = 0;
	public static final String ID_COLUMN = COCTAILS_COLUMNS[ID_COLUMN_INDEX];

	public static final int NAME_COLUMN_INDEX = 1;
	public static final String NAME_COLUMN = COCTAILS_COLUMNS[NAME_COLUMN_INDEX];

	public static final int HISTORY_COLUMN_INDEX = 2;
	public static final String HISTORY_COLUMN = COCTAILS_COLUMNS[HISTORY_COLUMN_INDEX];

	public static final int INSTRUCTION_COLUMN_INDEX = 3;
	public static final String INSTRUCTION_COLUMN = COCTAILS_COLUMNS[INSTRUCTION_COLUMN_INDEX];

	public static final int IMAGE_COLUMN_INDEX = 4;
	public static final String IMAGE_COLUMN = COCTAILS_COLUMNS[IMAGE_COLUMN_INDEX];

	public static CoctailDb getCoctail(Cursor cursor) {
		Long id = (long) cursor.getInt(ID_COLUMN_INDEX);
		String name = cursor.getString(CoctailsTable.NAME_COLUMN_INDEX);
		String history = cursor.getString(CoctailsTable.HISTORY_COLUMN_INDEX);
		String instruction = cursor
				.getString(CoctailsTable.INSTRUCTION_COLUMN_INDEX);
		String imagePath = cursor.getString(CoctailsTable.IMAGE_COLUMN_INDEX);
		return new CoctailDb(name, instruction, history, imagePath, id);
	}

	public static ContentValues getContentValues(CoctailDb coctail) {
		ContentValues contentValues = new ContentValues();
		contentValues.put(NAME_COLUMN, coctail.getName());
		contentValues.put(HISTORY_COLUMN, coctail.getHistory());
		contentValues.put(INSTRUCTION_COLUMN, coctail.getDrinkInstruction());
		contentValues.put(IMAGE_COLUMN, coctail.getImagePath());

		return contentValues;
	}
}
